<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Attestation_type_model extends CI_Model {
	function __construct(){
        parent::__construct();
    }

    function add($data = array()){
    	$this->db->insert('zjy_attestation_type', $data);
		return $this->db->affected_rows();
    }

    function update($data = array(),$where=array()){
    	if(!empty($where)){
    		$this->db->where($where);
    	}
		$this->db->update('zjy_attestation_type', $data);
		return $this->db->affected_rows();
    }

    function get_one($where = array(),$select='*'){
		$this->db->select($select);
		if(!empty($where)){
			$this->db->where($where);
		}
		$this->db->limit(1);
		$query = $this->db->get('zjy_attestation_type');
		return $query->row_array();
	}

	public function get_list($where = array(),$select='*'){
		$this->db->select($select);
		if(!empty($where)){
			$this->db->where($where);
		}
		$query = $this->db->get('zjy_attestation_type');
		return $query->result_array();
	}



    function get_datum_list($parms=array(),$per_page=0,$page_size=10){
    	$tmp = array();
		foreach($parms as $key => $val){
			if($val){
					$tmp[] = "{$key} = '{$val}'";
				}
		}

		$select = "*";
		$where = '';
		$tmp && $where = " where " . implode(' and ', $tmp);
		$order = "order by type_id desc";

		$sql = "select {$select} from zjy_attestation_type {$where} {$order}";
		$limit = " limit {$per_page},{$page_size}";
		$sql .= $limit;
		$query = $this->db->query($sql);
		$data['list'] = $query->result_array();

		$sql = "select count(*) as count from zjy_attestation_type {$where}";
		$query = $this->db->query($sql);
		$data['count'] = $query->row()->count;
		return $data;
    }


	function get_id_names(){
		$key = 'zjy_attestation_type';
		$list = $this->mycache->get_array($key);
		if(!$list){
			$query = $this->db->get('zjy_attestation_type');
			$result = $query->result_array();
			$list = array();
			foreach($result as $val){
				$val['fstatus'] == 1 and $list[$val['type_id']] = $val['name'];
			}
			$this->mycache->set_array($key,$list,0);
		}
		return $list;
	}

}